package com.syqc.custom

import android.content.Context
import android.content.res.TypedArray
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import com.syqc.monitor.R
import com.syqc.monitor.databinding.LayoutTyreBinding

class TyreView : FrameLayout {
    constructor(context: Context) : super(context) {
        initView(context, null)
    }

    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
        initView(context, attrs)
    }

    constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(
        context,
        attrs,
        defStyle
    ) {
        initView(context, attrs)
    }


    private lateinit var binding: LayoutTyreBinding
    private fun initView(context: Context, attrs: AttributeSet?) {
        binding = LayoutTyreBinding.inflate(LayoutInflater.from(context), this, true)
        val typedArray: TypedArray =
            context.obtainStyledAttributes(attrs, R.styleable.psi_view)
        val psiNum = typedArray.getString(R.styleable.psi_view_psiNum)
        binding.tvTyreNum.text = psiNum
        typedArray.recycle()
    }

    fun showPsi(isTyre: Boolean) {
        binding.llTyre.setBackgroundResource(if (isTyre) R.mipmap.ic_tyre_green else R.mipmap.ic_tyre_black)
    }

    fun setTyrePsi(value:String){
        binding.tvTyrePsi.text=value
    }
    fun setTyreTemp(value:String){
        binding.tvTyreTemp.text=value
    }


}